from SoAnalyser import SoAnalyser
import argparse
import json
provide_pkg_id = "libarchive13_3.2.1-2~ubuntu16.04.1_amd64"
provide_pkg_dir = "./" + provide_pkg_id
require_pkg_id = "libarchive-tools_3.2.1-2~ubuntu16.04.1_amd64"
require_pkg_dir = "./" + require_pkg_id


if __name__ == "__main__":
    provide_pkg_id = "libarchive13_3.2.1-2~ubuntu16.04.1_amd64"
    require_pkg_id = "libarchive-tools_3.2.1-2~ubuntu16.04.1_amd64"
    parser = argparse.ArgumentParser()  # 创建一个解析对象
    parser.add_argument('-p', '--provide_pkg_id', default=provide_pkg_id)
    parser.add_argument('-r', '--require_pkg_id', default=require_pkg_id)
    args = parser.parse_args()
    depend_graph = {}
    depend_graph[f'{require_pkg_id} --[:Depends On]-> {provide_pkg_dir}'] = \
        SoAnalyser.find_depend_graph(args.provide_pkg_id, args.require_pkg_id)
    with open('call_graph.json', 'w', encoding='utf-8') as f:
        json_str = json.dumps(depend_graph, indent=2)
        f.write(json_str)
    print("function call graph saved ad call_graph.json")


